package com.jackie.tongzhuang.Classes;


import com.jackie.tongzhuang.Enums.Constants;
import com.jackie.tongzhuang.Models.FenQi;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class BusinessClass {
    public static List<FenQi> getFenQi(double jinE, int qiShu) {
        List<FenQi> fqs = new ArrayList<>();
        double fenqi_jine = jinE / qiShu;
        for (int i = 0; i < qiShu; i++) {
            //
            Calendar c = Calendar.getInstance();
            if(Calendar.getInstance().get(Calendar.DAY_OF_MONTH)<=Constants.MeiYueFenQuRi) {
                c.add(Calendar.MONTH, i + 1);
            }else{
                c.add(Calendar.MONTH, i + 2);
            }
            //
            double je = BaseClass.getDecimal(2, fenqi_jine);
            double lx = getDengEBenXi(jinE, Constants.liLv,qiShu);

            FenQi fq = new FenQi();
            fq.setQiShu(String.valueOf(i + 1));
            fq.setFenQiRiQi(BaseClass.getDate());
            fq.setFenQiJinE(je+lx);
            fq.setBenJin(je);
            fq.setLiXi(lx);
            fq.setYiChangHuan(0);
            fq.setChangHuanRiQi(BaseClass.getDate(c));
            fqs.add(fq);

        }
        return fqs;
    }

    public static List<FenQi> getZaiFenQi(double jinE, int qiShu,String fqqs,int jhdid) {
        List<FenQi> fqs = new ArrayList<>();
        double fenqi_jine = jinE / qiShu;
        for (int i = 0; i < qiShu; i++) {
            //
            Calendar c = Calendar.getInstance();
            if(Calendar.getInstance().get(Calendar.DAY_OF_MONTH)<=Constants.MeiYueFenQuRi) {
                c.add(Calendar.MONTH, i + 1);
            }else{
                c.add(Calendar.MONTH, i + 2);
            }
            //
            double je = BaseClass.getDecimal(2, fenqi_jine);
            double lx = getDengEBenXi(jinE, Constants.liLv,qiShu);

            FenQi fq = new FenQi();
            fq.setQiShu(fqqs+"-"+String.valueOf(i + 1));
            fq.setFenQiRiQi(BaseClass.getDate());
            fq.setFenQiJinE(je+lx);
            fq.setBenJin(je);
            fq.setLiXi(lx);
            fq.setYiChangHuan(0);
            fq.setChangHuanRiQi(BaseClass.getDate(c));
            fq.setJinHuoDanId(jhdid);
            fqs.add(fq);

        }
        return fqs;
    }

    public static double getDengEBenXi(double benJin,double liLv,int qiShu){
        double ylx = benJin * liLv / 12;
        return Double.valueOf(BaseClass.getDecimal(2).format(ylx));
    }




}
